package com.augurit.common.tag.button;

import java.io.Writer;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.struts2.components.Component;

import sun.reflect.generics.tree.Tree;

import com.opensymphony.xwork2.util.ValueStack;

/**
 * Buttons的业务逻辑Bean
 * 
 * @author Administrator
 * 
 */
public class Buttons extends Component {

	private String name;
	private String id;
	private String sessionPrivilege;
	private String onclick;
	private String disabled;
	private String value;
	private String accesskey;
	private String debug; //调试，显示当前权限
	private String onblur;
	private String onkeydown;
	private String onkeypress;
	private String onkeyup;
	private String width;
	private String align;
	private String style;
	private String size;
	private String height;
	
	public String getHeight() {
		return height;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public String getOnblur() {
		return onblur;
	}

	public String getOnkeydown() {
		return onkeydown;
	}

	public String getOnkeypress() {
		return onkeypress;
	}

	public String getOnkeyup() {
		return onkeyup;
	}

	public String getWidth() {
		return width;
	}

	public String getStyle() {
		return style;
	}

	public String getSize() {
		return size;
	}

	public void setOnblur(String onblur) {
		this.onblur = onblur;
	}

	public void setOnkeydown(String onkeydown) {
		this.onkeydown = onkeydown;
	}

	public void setOnkeypress(String onkeypress) {
		this.onkeypress = onkeypress;
	}

	public void setOnkeyup(String onkeyup) {
		this.onkeyup = onkeyup;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public void setSize(String size) {
		this.size = size;
	}

	// 属性get和set方法
	public String getName() {
		return name;
	}

	public String getAccesskey() {
		return accesskey;
	}

	public void setAccesskey(String accesskey) {
		this.accesskey = accesskey;
	}
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
	public String getSessionPrivilege() {
		return sessionPrivilege;
	}

	public void setSessionPrivilege(String sessionPrivilege) {
		this.sessionPrivilege = sessionPrivilege;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public Buttons(ValueStack arg0) {
		super(arg0);
	}

	@Override
	public boolean start(Writer arg0) {
		boolean result = super.start(arg0);
		try {
			StringBuilder str = new StringBuilder();
			// 判断是否在权限内
			if (sessionPrivilege!=null && sessionPrivilege.indexOf("," + id + ",") >= 0) {
				str.append("<input type=\"button\" ");
				if (name != null) {
					str.append("name=\"" + name + "\"");
				}
				if (id != null) {
					str.append("id=\"" + id + "\"");
				}
				if (disabled != null) {
					str.append("disabled=\"" + disabled + "\"");
				}
				if (value != null) {
					str.append("value=\"" + value + "\"");
				}
				if (accesskey != null) {
					str.append("accesskey=\"" + accesskey + "\"");
				}
				if (onclick != null) {
					str.append("onclick=\"" + onclick + "\"");
				}
				if (height != null) {
					str.append("height=\"" + height + "\"");
				}
				if (onblur != null) {
					str.append("onblur=\"" + onblur + "\"");
				}
				if (onkeydown != null) {
					str.append("onkeydown=\"" + onkeydown + "\"");
				}
				if (onkeypress != null) {
					str.append("onkeypress=\"" + onkeypress + "\"");
				}
				if (onkeyup != null) {
					str.append("onkeyup=\"" + onkeyup + "\"");
				}
				if (width != null) {
					str.append("width=\"" + width + "\"");
				}
				if (align != null) {
					str.append("align=\"" + align + "\"");
				}
				if (style != null) {
					str.append("style=\"" + style + "\"");
				}
				if (size != null) {
					str.append("size=\"" + size + "\"");
				}
				str.append("/>");
				
			} else {
				str.append("");
			}
			if(debug != null && debug.equals("true")){
				String string = str.toString();
				str.append("</br>"+"<label>"+"该按扭的id是："+id
						+"；session所包含的权限为"+sessionPrivilege
						+"</label>"+"</br>");					
			}
			arg0.write(str.toString());
		} catch (Exception e) {
			Logger.getLogger(Tree.class.getName()).log(Level.WARN, null, e);
		}
		return result;

	}

	public String getDebug() {
		return debug;
	}

	public void setDebug(String debug) {
		this.debug = debug;
	}

	public String getAlign() {
		return align;
	}

	public void setAlign(String align) {
		this.align = align;
	}

	public String getId() {
		return id;
	}

	

}
